home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3310 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.1 KB  |  37 lines

  1. Path: prairienet.org!sjmccaug
  2. From: sjmccaug@prairienet.org (Scott J. McCaughrin)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Q:order of evaluation
  5. Date: 23 Jan 1996 10:58:12 GMT
  6. Organization: University of Illinois at Urbana
  7. Message-ID: <4e2f04$bnp@vixen.cso.uiuc.edu>
  8. References: <4dfhlu$a33$1@mhafn.production.compuserve.com>
  9. Reply-To: sjmccaug@prairienet.org (Scott J. McCaughrin)
  10. NNTP-Posting-Host: firefly.prairienet.org
  11.  
  12.  
  13. In a previous article, 100336.3326@CompuServe.COM (Holger Maier) says:
  14.  
  15. >Consider
  16. >#include <iostream>
  17. >int main() {
  18. >  int i=1;int j=i+(i+=1);
  19. >  cout<<i<<','<<j<<'\n';
  20. >  return 0;
  21. >}
  22. >on my compiler this produces 2,4
  23. >Looked up the ARM:
  24. >5: .. The order of evaluation of subexpressions is determined by the
  25. >precedence and grouping of operators.
  26. >5.7: The additive operators + and - group left to right.
  27. >So, j should be assigned 3 ??
  28.  
  29.  Hi, Holger:
  30.  
  31.  No, it appears that the compiler is correct. The parentheses override
  32.  any other precedence rules, so (i+=1) is executed first to set i == 2,
  33.  then the assignment has the effect of assigning i' + 2 (= 2 + 2) to j.
  34.  
  35.  -- Scott McC.
  36.  
  37.